package com.blb.zycommunity.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.blb.zycommunity.entity.SysUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.time.LocalDateTime;
import java.util.List;
import org.apache.catalina.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 用户信息表 Mapper 接口
 * </p>
 *
 * @author chenheng
 * @since 2023-11-20
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
     * 根据用户名查询用户信息
     * @param username
     * @return
     */
    SysUser selectUserByUsername(String username);
    /**
     * 用户管理分页
     * @param page
     * @return
     */
    IPage<SysUser> selectUserPage(IPage<SysUser> page, String deptName, String status, String userName, String phonenumber, LocalDateTime startTime, LocalDateTime finishTime);

    List<SysUser> selectPostByUserId(Long userId);

    List<SysUser> selectRoleByUserId(Long userId);
    @Update("update sys_user set status = #{status} where user_id = #{userId}")
    boolean updateUserStatus(@Param("status") String status,@Param("userId") Long userId);

    List<SysUser> selectUserSex();

    @Update("update sys_user set password = #{password} where user_id = #{userId}")
    boolean updateUserPassword(@Param("password") String password,@Param("userId") Long userId);

    @Update("update sys_user set del_flag = 2 where user_id = #{userId}")
    boolean deleteUser(@Param("userId") Long userId);

    @Update({
            "<script>",
            "update sys_user",
            "set del_flag = 2",
            "where user_id in",
            "<foreach item='userId' collection='userIds' open='(' separator=',' close=')'>",
            "#{userId}",
            "</foreach>",
            "</script>"
    })
    void batchDeleteUser(@Param("userIds") List<Long> userIds);



    IPage<SysUser> selectUserPage(IPage<SysUser> page,String deptName);
    /**
     * 根据用户名修改用户信息
     * @param sysUser
     * @return
     */
    SysUser editByUsername(SysUser sysUser);

    /**
     * 根据用户名查询用户个人信息
     * @param username
     * @return
     */
    List<SysUser> selectInformationByUsername(String username);

    SysUser excelUserById(Long userId);
}
